/*
 * @Author: Mr.Hope
 * @Date: 2019-06-26 20:26:14
 * @LastEditors: Mr.Hope
 * @LastEditTime: 2019-11-20 17:46:02
 * @Description: Vuex ImagePreview Module
 */
import Vue from 'vue';

export interface DocState {
  /** 内部文档列表 */
  compiledDoc: Record<string, string>;
  /** 文档加载状态 */
  docLoading: boolean;
  /** 登录状态 */
  loginStatus: Record<string, boolean>;
  /** 密码存储 */
  password: Record<string, string>;
}

/** 初始状态 */
const docState: DocState = {
  compiledDoc: {},
  docLoading: true,
  loginStatus: {},
  password: {}
};

export default {
  state: docState,
  mutations: {
    /**
     * 储存编译好的文档页面
     *
     * @param state state
     * @param compiledDoc [文档页面路径, 文档页面html string]
     */
    compiledDoc(state: DocState, compiledDoc: string[]) {
      Vue.set(state.compiledDoc, compiledDoc[0], compiledDoc[1]);
    },

    /**
     * 设置登陆状态
     *
     * @param state state
     * @param key login标识符
     */
    login(state: DocState, key: string) {
      state.loginStatus[key] = true;
    },

    /**
     * 设置密码
     *
     * @param state state
     * @param msg 密码详情
     */
    password(state: DocState, msg: string[]) {
      state.password[msg[0]] = msg[1];
    },

    /**
     * 设置加载文档状态
     *
     * @param state state
     * @param docLoading 文档加载状态
     */
    loadDoc(state: DocState, docLoading: boolean) {
      state.docLoading = docLoading;
    }
  }
};
